package com.example.examapp.controller;

import com.example.examapp.enums.QuestionType;
import com.example.examapp.model.Question;
import com.example.examapp.service.QuestionService;
import org.lzx.base.common.Result;
import org.lzx.base.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version v1.0
 * @package com.example.examapp.controller
 * @data 2022/12/4 11:04
 */
@RestController
@RequestMapping("/ques")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    @PostMapping("/save")
    public Result save(@RequestBody Question question){
        return ResultUtil.success(questionService.save(question));
    }

    @GetMapping("/findById/{id}")
    public Result getById(@PathVariable("id")String id){
        return  ResultUtil.success(questionService.getById(id));

    }

    @GetMapping("/list")
    public Result list(){
        return ResultUtil.success(questionService.queryAll());
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id")String id){
        return ResultUtil.success(questionService.del(id));
    }

    @GetMapping("/{type}")
    public Result findByType(@PathVariable("type") QuestionType type){
        return ResultUtil.success(questionService.findByType(type));

    }
}
